const cinemasModel = require('../model/cinemasModel');

//查询
//查询所有
module.exports.find = async function (cinemasObj, page) {
    //分页查询
    let { current, size } = page;
    let total = await cinemasModel.countDocuments(cinemasObj);
    let totalPage = Math.ceil(total / size);
    let rows = await cinemasModel.find(cinemasObj).limit(parseInt(size)).skip((current - 1) * size); // 返回数组
    return { current, size, total, totalPage, rows };
}
//id查询
module.exports.findById = async function (id) {
    return await cinemasModel.findById(id); // 返回对象，若找不到，返回 null;
}
module.exports.findAll = async function (cinemasObj) {
    return await cinemasModel.find(cinemasObj); // 返回对象，若找不到，返回 null;
}

//新增
module.exports.insert = async function (cinemas) {
    return await cinemasModel.create(cinemas);
}

//删除
module.exports.delete = async function (id) {
    return await cinemasModel.deleteOne({ _id: id });
}

//修改
module.exports.update = async function (id, cinemas) {
    return await cinemasModel.updateOne({ _id: id }, cinemas);
}